<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Twei后台登录界面</title>
    <link rel="stylesheet" href="css/index.css">
    <link rel="shortcut icon"
          href="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/basic/favicon.ico">
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="./css/mouse.css">
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script src="http://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>

    <style>
        html, body {
            width: 100%;
            height: 100%;
            background: linear-gradient(to bottom, #7474BF, #348AC7) no-repeat center center fixed;
            background-size: 100% 100%;
        }
    </style>
</head>
<body>
<canvas class="cavs" width="1575" height="1337"></canvas>

<script>
    $(document).ready(function () {
        setInterval(function gets() {
            $.ajax({
                url: "https://tenapi.cn/acg/?return=json",
                dataType: 'json',
                type: "GET",
                async: true,
                success: function (data) {
                    if (data.code === 200) {
                        $("body").css("background", "url(" + data.imgurl + ")")
                    }
                }
            });
        }, 3500);
    });

</script>
<div class="loginmain">
    <div class="login-title">
        <span>管理员登录</span>
    </div>

    <div class="login-con">
        <div class="login-user">
            <div class="icon">
                <img src="images/user_icon_copy.png" alt="">
            </div>
            <input id="username" type="text" name="usernem" placeholder="用户名" autocomplete="off" value="">
        </div>
        <div class="login-pwd">
            <div class="icon">
                <img src="images/lock_icon_copy.png" alt="">
            </div>
            <input id="password" type="password" name="pwd" placeholder="密码" autocomplete="off" value="">
        </div>
        <div class="login-btn">
            <input type="button" value="登录" id="login">
        </div>
        <script>
            $(document).keydown(function (event) {
                if (event.keyCode === 13) {
                    $('#login').triggerHandler('click');
                }
            });
        </script>
    </div>

</div>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script type="text/javascript">

    layui.use(['jquery', 'layer'], function () {
        var $ = layui.jquery,
            layer = layui.layer;

        function judgeuser(username) {
            let resultdata = null;
            $.each(JSON.parse(JSON.stringify(layui.data("twei").user)), function (index, item) {
                if (username === item.username) {
                    resultdata = {psw: item.password, auth: item.authority};
                }
            });
            return resultdata;
        }

        // JSON.parse(JSON.stringify(layui.data("twei").user)).splice(2, 1);

        // let jsonDatas = JSON.parse(JSON.stringify(layui.data("twei").user));
        // jsonDatas.push({username: 'admin', password: "123456", authority: 1});


        $("#login").click(function () {
            let username = $("#username").val();
            let password = $("#password").val();
            if (username === "" || username == null) {
                layer.msg("请输入用户名", {icon: 2, time: 800});
            } else if (password === "" || password == null) {
                layer.msg("请输入密码", {icon: 2, time: 800});
            } else {
                let userdata = judgeuser(username);
                console.log(userdata)
                if (userdata != null) {
                    if (userdata.psw === md5(password)) {
                        if (userdata.auth === 1) {
                            layer.msg("登录成功", {icon: 1, time: 800}, function () {
                                layui.data('twei', {
                                    key: 'rootuser'
                                    , value: {username: username}
                                });
                                window.location.href = 'adminindex.html';
                            });
                        } else {
                            layer.msg("您的账号不允许登录！", {icon: 2, time: 800});
                        }

                    } else {
                        layer.msg("密码错误", {icon: 2, time: 800});
                    }

                } else {
                    layer.msg("用户不存在，请注册", {icon: 2, time: 800});
                }
            }
        });
    });
</script>
</body>
</html>
<script src="./js/mouse.js"></script>
<script src="js/ban.js"></script>